<template>
  <router-link to="/order/index" class="my-order" v-if="isLogin"> 
    <i class="i-order"></i>
    {{$t('index.order.my_order')}}
    <div class="right-btn">{{number || orderNumber}}</div>
  </router-link>
</template>

<script>
import { getOrderList } from '@/api/c'
import { mapGetters } from 'vuex'

export default {
  name: 'MyOrderBtn',
  props: {
    number: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      orderNumber: 0
    }
  },
  computed: {
    ...mapGetters([
      'isLogin'
    ])
  },
  created() {
    this.isLogin && this.getList()
  },
  methods: {
    getList() {
        getOrderList().then(response => {
            this.orderNumber = response.data ? response.data.total: 0
        })
      }
  }
}
</script>
<style scoped>
  .my-order {
    display: inline-block;
    width: 176px;
    height: 40px;
    line-height: 40px;
    background: #FFB73E;
    border-radius: 4px;
    font-size: 12px;
    padding-left: 25px;
    position: absolute;
    right: 0;
    bottom: 0;
    color: #ffffff;
  }
  .my-order .i-order {
    margin-right: 12px;
    display: inline-block;
    background: url('../../assets/index-order.png') no-repeat center;
    background-size: contain;
    vertical-align: middle;
    width: 14px;
    height: 16px;
  }
  .right-btn {
    background: #FFA000;
    border-top-right-radius: 4px;
    border-bottom-right-radius: 4px;
    position: absolute;
    right: 0;
    top: 0;
    width: 50px;
    text-align: center;
  }
</style>
